package com.lagou.homework3.three;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class StudentTest {
    public static void main(String[] args) {
        Map<Student,String> map1 = new HashMap<>();
        Student st1 = new Student("liyulin",28);
        Student st2 = new Student("zhanfei",1000);

        map1.put(st1,"江西省宜春市新昌镇");
        map1.put(st2,"中国云南省某某镇");

        //第一种方式
        map1.forEach((k,v)->{
            System.out.println(k + "::" + v);
        });
        System.out.println("---------------------------");
        //第二种方式迭代器
        Set<Student> students = map1.keySet();
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()){
            Student s1 = iterator.next();
            System.out.println(s1+ "::" + map1.get(s1));
        }
        System.out.println("----------------------------");
        //第三种方式使用
        Set<Map.Entry<Student, String>> entries = map1.entrySet();
        for (Map.Entry<Student, String> e: entries) {
            System.out.println(e.getKey()+ "::" + e.getValue());
        }
        System.out.println("----------------------------");
        //第四种
        Set<Student> students2 = map1.keySet();
        for (Student e:students) {
            System.out.println(e.toString() + "::" + map1.get(e));
        }

    }
}
